<#assign object = doc.objects>
package ${object.package}.gwt.client;

import redora.client.model.AttributeFieldsView;
import redora.client.upgrade.RedoraConfigurationViewPanel;
import redora.client.tagging.AboutPanel;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FlexTable;

public class GWTShowcase implements EntryPoint {

	public void onModuleLoad() {

		final DecoratedTabPanel dataTp = new DecoratedTabPanel();
		<#list object["/objects/object/name"] as objectName>
		final ${objectName}ViewPanel ${objectName?uncap_first}Panel = new ${objectName}ViewPanel();
		dataTp.add(${objectName?uncap_first}Panel, "${objectName}");
		</#list>
		dataTp.setHeight("500");
		dataTp.setWidth("100%");
		dataTp.setVisible(true);
		dataTp.addSelectionHandler(new SelectionHandler<Integer>() {

			public void onSelection(SelectionEvent<Integer> arg0) {
				<#assign num = 0>
				<#list object["/objects/object/name"] as objectName>
				if(arg0.getSelectedItem() == ${num}) {
					${objectName?uncap_first}Panel.setVisible(true);
				}
				<#assign num = num + 1>
				</#list>
			}

		});
		dataTp.selectTab(0);

		final DecoratedTabPanel attributeTp = new DecoratedTabPanel();
		<#list object["/objects/object/name"] as objectName>
		attributeTp.add(new AttributeFieldsView("${objectName}"), "${objectName}");
		</#list>
		attributeTp.setHeight("500");
		attributeTp.setWidth("100%");
		attributeTp.setVisible(false);
		attributeTp.addSelectionHandler(new SelectionHandler<Integer>(){

			public void onSelection(SelectionEvent<Integer> arg0) {
				AttributeFieldsView panel = (AttributeFieldsView) attributeTp
						.getWidget(arg0.getSelectedItem());
				panel.setVisible(true);
			}
			
		});
		attributeTp.selectTab(0);
		
		final FlowPanel upgradeFp = new FlowPanel();
		final RedoraConfigurationViewPanel redoraConfigurationViewPanel = new RedoraConfigurationViewPanel();
		upgradeFp.add(redoraConfigurationViewPanel);
		upgradeFp.setVisible(false);
		
		final AboutPanel aboutPanel = new AboutPanel();
		aboutPanel.setVisible(false);

		FlexTable table = new FlexTable();

        HTML modelLink = new HTML("<a href=javascript:void(0)>Model</a>");

        modelLink.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent arg0) {
                dataTp.setVisible(false);
                attributeTp.setVisible(true);
                upgradeFp.setVisible(false);
                aboutPanel.setVisible(false);
            }

        });
        table.setWidget(0, 0, modelLink);

        HTML dataLink = new HTML("<a href=javascript:void(0)>Data</a>");
        dataLink.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent arg0) {
                dataTp.setVisible(true);
                attributeTp.setVisible(false);
                upgradeFp.setVisible(false);
                aboutPanel.setVisible(false);
            }

        });
        table.setWidget(0, 1, dataLink);

        HTML upgradeLink = new HTML("<a href=javascript:void(0)>Upgrade</a>");
        upgradeLink.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent arg0) {
                dataTp.setVisible(false);
                attributeTp.setVisible(false);
                upgradeFp.setVisible(true);
                redoraConfigurationViewPanel.setVisible(true);
                aboutPanel.setVisible(false);
            }

        });
        table.setWidget(0, 2, upgradeLink);

        HTML aboutLink = new HTML("<a href=javascript:void(0)>About</a>");
        aboutLink.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent arg0) {
                dataTp.setVisible(false);
                attributeTp.setVisible(false);
                upgradeFp.setVisible(false);
                aboutPanel.setVisible(true);
            }

        });
        table.setWidget(0, 3, aboutLink);
        table.setHeight("20");

		VerticalPanel panel = new VerticalPanel();
		panel.setHeight("700");
		panel.setWidth("100%");

		RootPanel.get().add(panel);
		panel.add(table);

		VerticalPanel showPanel = new VerticalPanel();
		showPanel.add(dataTp);
		showPanel.add(attributeTp);
		showPanel.add(upgradeFp);
		showPanel.add(aboutPanel);
		showPanel.setWidth("100%");
		showPanel.setHeight("100%");

		panel.add(showPanel);
		RootPanel.getBodyElement().removeChild(RootPanel.get("loadingWrapper").getElement());
	}
}